﻿using System.Collections.Generic;
using System.Linq;
using DataBaseLayer.Dto;

namespace DataBaseLayer.Extensions
{
	public static class ScheduleDayEx
	{
		public static ScheduleDayData ToDTO(this ScheduleDay entity)
		{
			if (entity == null) return null;

			var dto = new ScheduleDayData
			{
				Date = entity.Date,
				Day = entity.Day,
				DayId = entity.DayId,
				IsSpecialDay = entity.IsSpecialDay,
				ScheduleServices = entity.ScheduleServices.OrderBy(ss => ss.Time).ToDTOs()
			};

			return dto;
		}

		public static List<ScheduleDayData> ToDTOs(this IEnumerable<ScheduleDay> entities)
		{
			if (entities == null) return null;

			return entities.Select(e => e.ToDTO()).ToList();
		}
	}
}
